home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / UTIL / DESKTOP / BLACKHOLE / !BlakHole2 / !FatHelp / Help / WriteA < prev    next >
Text File  |  1995-12-27  |  7KB  |  102 lines

  1. {title}How to write your own Action
  2. [1]
  3. Don't try this, you'll confuse yourself.
  4. [234]
  5. You can add an Action to the file finder if you know any BASIC.
  6. The file finder was not designed with this in mind, so it's not necessarily the most obvious or easy extension system in the world. In fact, it's downright awful. But. Anyway. It's not that difficult.
  7. There are three parts to the file finder:
  8. 1) The search engine scans the disc looking for a file that matches the given name, type and size.
  9. 2) The matching file is passed to the Action which does with it what it will.
  10. 3) If 'Create List' is selected (the variable file%=TRUE) and the Action has not forbidden it, the name of the file is added to the list.
  11. All the Action needs to do is:
  12. Have some code to initialise itself (most actions have nothing).
  13. Have some code to verify that any parameters are correct.
  14. Have some code to act on the found files.
  15. You will see from the above that it is possible to write an Action that acts as a filter - e.g. checking datestamps or file contents. It should be very easy to do this.
  16. {subhead}Structure
  17. An Action is a fragment of a BASIC program. It must contain three procedures.
  18. These are:
  19. {subsub}DEFFNoktoproceed
  20. This works out whether it is ok to start the find. The FN returns TRUE if it is, or FALSE otherwise. In normal circumstances this should simply contain the line
  21. =TRUE
  22. But you can use this to ask the user if they wish to continue by doing:
  23. PROClamation("Some Text requiring a yes/no answer",-1,6)
  24. IF query%=0 THEN=FALSE ELSE=TRUE
  25. which will pop up a question box. If the user clicks 'No' the search will not be allowed to start.
  26. You may also want to check that some condition is true before you start. For instance, some Actions can take parameters, which are entered in the writable icons in the window. You may need to check that the parameters are correct:
  27. The parameters are stored in parameter$(0) - parameter$(10) so you can do
  28. <Check that parameter is valid>
  29. IF <parameter not valid> PROClamation("Error message",0,0):=FALSE
  30. =TRUE
  31. The call to PROClamation opens an error box informing the user that they are an idiot.
  32. {subsub}DEFPROCinitfind
  33. This is called just before the find starts, but after PROCoktoproceed. You can use this to check that all is still well. If, having done this, you want the search to carry on, include
  34. flag%=TRUE (this is the normal case).
  35. else include
  36. flag%=FALSE
  37. If it is essential that your Action produces a list of files, (for example if
  38. you are writing a filter) then you MUST include the lines
  39. file%=TRUE
  40. PROCselic(Mavis%,29,0,high)
  41. which sets the flag and selects the icon to be ON. The 'List Details' action does this (and nothing else).
  42. {subsub}DEFPROCaction(directory$,filename$
  43. {subsub}objtype%,filetype%,ssize%)
  44. Once a matching file has been found the details are passed to PROCaction.
  45. The variables are:
  46. directory$ : The directory containing the file
  47. filename$ : The name of the file (without the directory)
  48. objtype% : Which is 1 if the object is a file, 2 if it's an application
  49.              or directory, and 3 if it's an image file.
  50. filetype% : The file type of the file (eg &FFF for text files).
  51. ssize% : (note the double s) is the size of the file, in bytes.
  52. You may do anything you like with this information.
  53. If you decide that the file you've got is not suitable and you don't want it to count towards the total files found, include the lines:
  54. totalsize%-=ssize%
  55. tot%-=1
  56. addtolist%=FALSE
  57. The last line informs the main routine that this file has been decided against and should not be included in a list, even if Create List is selected.
  58. If you want extra information to be added to the list after the name of
  59. the file, PROCaction should set the variable
  60. extrainfo%=TRUE
  61. you must then provide
  62. FNextrainfo(directory$,filename$,objtype%,filetype%,ssize%)
  63. which returns a text string containing the extra info. This text can be anything at all. You can have more than one line of extra information. When you have returned your last piece of information you MUST set
  64. extrainfo%=FALSE
  65. {subhead}Important bits:
  66. The first few lines of your Action MUST be REM statements in the following form:
  67. {tab}
  68. REM Action:<Name of action>
  69. REM Data:<data description> (Optional)
  70. REM Data:<more description> (Optional)
  71. REM Data:None
  72. {notab}
  73. <Name of action> is what will appear in the Action menu.
  74. If you don't want any parameters, you should just include Data:None
  75. THE Data AND THE None ARE CASE SENSITIVE!!!!!
  76. If you do want to have parameters, you should make <data description> a short (about 20 characters or less) description of what the data is. This will be the label for the writable icon. The file finder will create one writable icon for each Data: item you specify.
  77. You can also get the file finder to create an Option icon instead of a writeable icon + lable by using the format:
  78. REM Data:<data description>,YesNo
  79. or
  80. REM Data:<data description>,NoYes
  81. The difference between the two is that a YesNo icon will have its default state as 'Yes' and will set the relevant parameter$() variable to "0" for Yes and "1" for No. A NoYes icon default to 'No' and returns "0" for No and "1" for Yes. Confusing, isn't it? The FindDup (Find Duplicate Files) Action uses two option icons.
  82. None MUST BE THE LAST ITEM OF DATA!!!
  83. The Set Type Action uses a parameter. Looking in there is probably much easier than me explaining it.
  84. Save your file with any name you like in the directory !BlakHole2.!FileFind.Actions.
  85. {subhead}Potentially useful bits
  86. To save you having to reproduce any of my hard (if shoddy) work, somePROCs that may be of use are:
  87. {tab}
  88. {subsub}FNreadvar(var$)
  89. which reads the value of a system variable, returning the value as a string.
  90. {subsub}PROClamation
  91. which has been discussed above.
  92. {subsub}FNftype
  93. which takes a string and attempts to evaluate it to see if it corresponds to a known filetype. E.g. if passed the string 'text' it would return the string 'FFF'. If passed a null string, it will return a null string without causing an error, so you should check for this. If the string passed to it cannot be evaluated it will generate an error and set the variable wrinkledforeskin% to FALSE. This variable is TRUE otherwise.
  94. {subsub}Scrap Buffer
  95. There is an 8000 byte scrap buffer available for use. It is pointed to by the variable scrap2%
  96. {notab}
  97. Feel free to examine the program for any more bits. Beware of the appalling
  98. coding and dreadful variable names. Do not alter the program in any way.
  99. If you write a new Action do two things:
  100. Send me a copy so I can include it (with a credit) in future releases. Accept that I can take no responsibility for maintaining it or for anything which might go wrong with it.
  101. {centre}Bye.
  102.